@echo off
setlocal enabledelayedexpansion

for %%i in ("%cd%") do set "parent_dir=%%~nxi"

for /f %%i in ('powershell -NoProfile -Command "Get-Date -Format yyMMdd"') do set date=%%i

set seq=1

:check_version

set seq_str=%seq%

if %seq% lss 10 set seq_str=0%seq%

set version=%date%%seq_str%

docker images | findstr /r /c:"hub.tangjiabin.cn/jymj/%parent_dir% *%version%" >nul
if %errorlevel%==0 (
    set /a seq+=1
    goto check_version
)

echo.
echo 开始构建 Docker 镜像 %parent_dir%:%version%
echo.

docker build -t %parent_dir%:%version% .
if %errorlevel% neq 0 exit /b

echo.
echo 推送到 hub.tangjiabin.cn/jymj/%parent_dir%:%version%
echo.

docker tag %parent_dir%:%version% hub.tangjiabin.cn/jymj/%parent_dir%:%version%
if %errorlevel% neq 0 exit /b

docker push hub.tangjiabin.cn/jymj/%parent_dir%:%version%
if %errorlevel% neq 0 exit /b

echo.
echo hub.tangjiabin.cn/jymj/%parent_dir%:%version% 构建并推送成功
echo.

pause